<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="header/h5header::h5header('回复','','')">
</head>

<body>
<!-- 正文 -->
<div class="Headline">
    <div class="indexHeadline">
        <div class="Headline-tReply">
            <a th:href="'/details/' + ${article}" class="Headline-tReplyA">
            	<i class="iconfont">&#xe602;</i>
            </a>
            <h3 class="Headline-tReplyH4">评论回复</h3>
            <a href="javascript:;" id="sendmsg" class="Headline-tReplyA2">发送</a>
        </div>
    </div>

    <!--回复消息列表-->
    <div class="CommentMsg ReplyList">
		<input type="hidden" th:value="${article}" id="articleId">
		<input type="hidden" th:value="${pcid}" id="pcid">
		<input type="hidden" th:value="${acid}" id="acid">
		<input type="hidden" th:value="${touserId}" id="touserId">
		<input type="hidden" th:value="${name}" id="userName">
        <div class="inputReply">
            <div class="inputReply-text">
                <textarea name="retInputV" id="retInputV" autofocus="autofocus" maxlength="50" th:text="'回复@' + ${name} + '：'"></textarea>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
layui.use(['layer', 'setter', 'mynotice', 'admin', 'ax', 'util'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var setter = layui.setter;
    var mynotice = layui.mynotice;
    var admin = layui.admin;
    var $ax = layui.ax;
    var util = layui.util;
    
    var Reply = {
   		addReply: () => { // 回复
   			var ajax = new $ax('/zp/comment/add', 'post', function (res) {
   				window.location.href=document.referrer;
   			}, function (res) {
   				mynotice.error(res.msg);
   			});
   			var content = $('#retInputV').val();
   			if(content == ''){
 	        		mynotice.infoc('请输入回复内容！');
 	        		return false;
 	        	}
   			var data = {};
   			data['articleId'] = $('#articleId').val();
   			
            // 回复用户昵称
            var oHfName = $('#userName').val();
            // 回复用户的Id
            var touserId = $('#touserId').val();
            var pcid = $('#pcid').val();
            var acid = $('#acid').val();
            var oAllVal = '回复@' + oHfName;
            //获取输入内容
            var oHfVal = $('#retInputV').val();
            data['touserId'] = touserId;
            data['pcid'] = pcid;
            data['acid'] = acid;
            oHfVal = oHfVal.replace(/^ +| +$/g,'');
            if(oHfVal == '' || oHfVal == oAllVal){
           		mynotice.infoc('请输入评论内容！');
 	        	return false;
            }
            var tores = {};
            var arr;
            var ohfNameArr;
            if(oHfVal.indexOf("@") == -1){
           	 tores['atName'] = '';
           	 tores['hfContent'] = oHfVal;
            }else {
                arr = oHfVal.split('：');
                ohfNameArr = arr[0].split('@');
                tores['hfContent'] = arr[1];
                tores['atName'] = ohfNameArr[1];
            }
            data['content'] = tores.hfContent;
            var ajax = new $ax('/zp/comment/reply', 'post', function (res) {
            	window.location.href=document.referrer;
		    }, function (res) {
		    	mynotice.error(res.msg);
		    });
   			ajax.setData(JSON.stringify(data));
   			ajax.start();
   		}
    }
    
    // 新增回复
    $('#sendmsg').on('click', function(){
    	Reply.addReply();
    })
	
});
</script>

</body>
</html>